@ibiz-template-plugin/ibiz-file-previewer 0.0.12 → 0.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.es.js +98 -68
- package/dist/index.legacy.js +1 -1
- package/dist/style.css +1 -1
- package/package.json +1 -1
package/dist/index.es.js
CHANGED
|
@@ -151,7 +151,7 @@ function O(n2, u2, t2, i2, o2, r2, e2, f2, c2, s2) {
|
|
|
151
151
|
else u2.__e = t2.__e, u2.__k = t2.__k, n3.then || z$1(u2);
|
|
152
152
|
l$3.__e(n3, u2, t2);
|
|
153
153
|
}
|
|
154
|
-
else null == r2 && u2.__v == t2.__v ? (u2.__k = t2.__k, u2.__e = t2.__e) : f2 = u2.__e = q$
|
|
154
|
+
else null == r2 && u2.__v == t2.__v ? (u2.__k = t2.__k, u2.__e = t2.__e) : f2 = u2.__e = q$1(t2.__e, u2, t2, i2, o2, r2, e2, c2, s2);
|
|
155
155
|
return (a2 = l$3.diffed) && a2(u2), 128 & u2.__u ? void 0 : f2;
|
|
156
156
|
}
|
|
157
157
|
function z$1(n2) {
|
|
@@ -172,7 +172,7 @@ function N$1(n2, u2, t2) {
|
|
|
172
172
|
function V$1(n2) {
|
|
173
173
|
return "object" != typeof n2 || null == n2 || n2.__b && n2.__b > 0 ? n2 : d$3(n2) ? n2.map(V$1) : w$2({}, n2);
|
|
174
174
|
}
|
|
175
|
-
function q$
|
|
175
|
+
function q$1(u2, t2, i2, o2, r2, e2, f2, c2, s2) {
|
|
176
176
|
var a2, h2, v2, y2, w2, _2, m2, b2 = i2.props || p$3, k2 = t2.props, x2 = t2.type;
|
|
177
177
|
if ("svg" == x2 ? r2 = "http://www.w3.org/2000/svg" : "math" == x2 ? r2 = "http://www.w3.org/1998/Math/MathML" : r2 || (r2 = "http://www.w3.org/1999/xhtml"), null != e2) {
|
|
178
178
|
for (a2 = 0; a2 < e2.length; a2++) if ((w2 = e2[a2]) && "setAttribute" in w2 == !!x2 && (x2 ? w2.localName == x2 : 3 == w2.nodeType)) {
|
|
@@ -303,11 +303,6 @@ function T$1(n2, r2) {
|
|
|
303
303
|
var u2 = p$2(t$1++, 7);
|
|
304
304
|
return C(u2.__H, r2) && (u2.__ = n2(), u2.__H = r2, u2.__h = n2), u2.__;
|
|
305
305
|
}
|
|
306
|
-
function q$1(n2, t2) {
|
|
307
|
-
return o$1 = 8, T$1(function() {
|
|
308
|
-
return n2;
|
|
309
|
-
}, t2);
|
|
310
|
-
}
|
|
311
306
|
function j$1() {
|
|
312
307
|
for (var n2; n2 = f$2.shift(); ) if (n2.__P && n2.__H) try {
|
|
313
308
|
n2.__H.__h.forEach(z), n2.__H.__h.forEach(B$1), n2.__H.__h = [];
|
|
@@ -18309,27 +18304,35 @@ const ThumbnailPanel = (props) => {
|
|
|
18309
18304
|
const [loadStates, setLoadStates] = d$2({});
|
|
18310
18305
|
const ITEM_HEIGHT = 188;
|
|
18311
18306
|
const BUFFER_COUNT = 1;
|
|
18312
|
-
const
|
|
18307
|
+
const phantomHeight = props.pages.length * ITEM_HEIGHT;
|
|
18313
18308
|
const [visibleRange, setVisibleRange] = d$2({ start: 0, end: 0 });
|
|
18314
|
-
const
|
|
18309
|
+
const [itemContainerOffsetY, setItemContainerOffsetY] = d$2(8);
|
|
18310
|
+
const calculateVisibleRange = (mode = "UI") => {
|
|
18315
18311
|
if (!contentRef.current) return { start: 0, end: 0 };
|
|
18316
18312
|
const container = contentRef.current;
|
|
18317
18313
|
const scrollTop = container.scrollTop;
|
|
18318
18314
|
const containerHeight = container.clientHeight;
|
|
18319
|
-
|
|
18320
|
-
|
|
18321
|
-
Math.floor(scrollTop / ITEM_HEIGHT) - BUFFER_COUNT
|
|
18322
|
-
|
|
18315
|
+
let start = 0;
|
|
18316
|
+
if (mode === "UI") {
|
|
18317
|
+
start = Math.max(0, Math.floor(scrollTop / ITEM_HEIGHT) - BUFFER_COUNT);
|
|
18318
|
+
} else {
|
|
18319
|
+
start = Math.max(0, props.currentPage - BUFFER_COUNT);
|
|
18320
|
+
}
|
|
18323
18321
|
const visibleCount = Math.ceil(containerHeight / ITEM_HEIGHT);
|
|
18324
18322
|
const end = Math.min(
|
|
18325
18323
|
props.pages.length,
|
|
18326
18324
|
start + visibleCount + BUFFER_COUNT
|
|
18327
18325
|
);
|
|
18328
18326
|
return { start, end };
|
|
18329
|
-
}
|
|
18330
|
-
const updateVisibleRange =
|
|
18331
|
-
|
|
18332
|
-
|
|
18327
|
+
};
|
|
18328
|
+
const updateVisibleRange = (mode) => {
|
|
18329
|
+
const range = calculateVisibleRange(mode);
|
|
18330
|
+
setItemContainerOffsetY(range.start * ITEM_HEIGHT + 8);
|
|
18331
|
+
setVisibleRange(range);
|
|
18332
|
+
};
|
|
18333
|
+
const throttleUpdateRange = throttle(() => {
|
|
18334
|
+
updateVisibleRange();
|
|
18335
|
+
}, 200);
|
|
18333
18336
|
const handleClick = (index, _event) => {
|
|
18334
18337
|
props.onPageClick(index);
|
|
18335
18338
|
};
|
|
@@ -18346,71 +18349,101 @@ const ThumbnailPanel = (props) => {
|
|
|
18346
18349
|
}
|
|
18347
18350
|
}
|
|
18348
18351
|
};
|
|
18349
|
-
const handleImageLoad = (
|
|
18352
|
+
const handleImageLoad = (page) => {
|
|
18350
18353
|
setLoadStates((prevState) => ({
|
|
18351
18354
|
...prevState,
|
|
18352
|
-
[
|
|
18355
|
+
[page.image_url]: true
|
|
18353
18356
|
}));
|
|
18354
|
-
setCachedImages((prev) => new Set(prev).add(index));
|
|
18355
18357
|
};
|
|
18356
|
-
const handleImageError = (
|
|
18358
|
+
const handleImageError = (page, error2) => {
|
|
18357
18359
|
setLoadStates((prevState) => ({
|
|
18358
18360
|
...prevState,
|
|
18359
|
-
[
|
|
18361
|
+
[page.image_url]: true
|
|
18360
18362
|
}));
|
|
18361
|
-
console.error("
|
|
18363
|
+
console.error("路径为".concat(page.image_url, "的图片加载失败,"), error2);
|
|
18362
18364
|
};
|
|
18363
|
-
const getLoadState = (
|
|
18364
|
-
return loadStates[
|
|
18365
|
+
const getLoadState = (imageUrl) => {
|
|
18366
|
+
return loadStates[imageUrl] || false;
|
|
18365
18367
|
};
|
|
18366
18368
|
y$1(() => {
|
|
18367
18369
|
const container = contentRef.current;
|
|
18368
18370
|
if (container) {
|
|
18369
18371
|
updateVisibleRange();
|
|
18370
|
-
container.addEventListener("scroll",
|
|
18372
|
+
container.addEventListener("scroll", throttleUpdateRange);
|
|
18371
18373
|
return () => {
|
|
18372
|
-
container.removeEventListener("scroll",
|
|
18374
|
+
container.removeEventListener("scroll", throttleUpdateRange);
|
|
18373
18375
|
};
|
|
18374
18376
|
}
|
|
18375
|
-
}
|
|
18377
|
+
});
|
|
18376
18378
|
y$1(() => {
|
|
18377
|
-
|
|
18379
|
+
var _a;
|
|
18380
|
+
const activeThumbnail = (_a = contentRef.current) == null ? void 0 : _a.querySelector(
|
|
18381
|
+
".thumbnail-item.active"
|
|
18382
|
+
);
|
|
18383
|
+
if (activeThumbnail) {
|
|
18384
|
+
scrollToCurrentThumbnail();
|
|
18385
|
+
} else {
|
|
18386
|
+
updateVisibleRange("DATA");
|
|
18387
|
+
setTimeout(() => {
|
|
18388
|
+
scrollToCurrentThumbnail();
|
|
18389
|
+
}, 0);
|
|
18390
|
+
}
|
|
18378
18391
|
}, [props.currentPage]);
|
|
18379
18392
|
return /* @__PURE__ */ u("div", { className: "thumbnail-panel", children: [
|
|
18380
18393
|
/* @__PURE__ */ u("div", { className: "thumbnail-panel-header", children: /* @__PURE__ */ u("h3", { children: "缩略图" }) }),
|
|
18381
|
-
/* @__PURE__ */ u("div", { className: "thumbnail-panel-content", ref: contentRef, children:
|
|
18382
|
-
|
|
18383
|
-
const isCached = cachedImages.has(index);
|
|
18384
|
-
const isVisible = visibleRange.start <= index && index <= visibleRange.end;
|
|
18385
|
-
return /* @__PURE__ */ u(
|
|
18394
|
+
/* @__PURE__ */ u("div", { className: "thumbnail-panel-content", ref: contentRef, children: [
|
|
18395
|
+
/* @__PURE__ */ u(
|
|
18386
18396
|
"div",
|
|
18387
18397
|
{
|
|
18388
|
-
|
|
18389
|
-
|
|
18390
|
-
|
|
18398
|
+
class: "thumbnail-panel-phantom",
|
|
18399
|
+
style: { height: "".concat(phantomHeight, "px") }
|
|
18400
|
+
}
|
|
18401
|
+
),
|
|
18402
|
+
/* @__PURE__ */ u(
|
|
18403
|
+
"div",
|
|
18404
|
+
{
|
|
18405
|
+
className: "thumbnail-item-container",
|
|
18406
|
+
style: {
|
|
18407
|
+
transform: "translate3d(0,".concat(itemContainerOffsetY, "px,0)")
|
|
18391
18408
|
},
|
|
18392
|
-
children:
|
|
18393
|
-
|
|
18394
|
-
(isVisible
|
|
18395
|
-
|
|
18409
|
+
children: props.pages && props.pages.length > 0 && props.pages.map((page, index) => {
|
|
18410
|
+
const isVisible = visibleRange.start <= index && index <= visibleRange.end;
|
|
18411
|
+
if (!isVisible) {
|
|
18412
|
+
return null;
|
|
18413
|
+
}
|
|
18414
|
+
const isLoaded = getLoadState(page.image_url);
|
|
18415
|
+
return /* @__PURE__ */ u(
|
|
18416
|
+
"div",
|
|
18396
18417
|
{
|
|
18397
|
-
|
|
18398
|
-
|
|
18399
|
-
|
|
18400
|
-
onLoad: () => {
|
|
18401
|
-
handleImageLoad(index);
|
|
18418
|
+
className: "thumbnail-item ".concat(page.index === props.currentPage ? "active" : ""),
|
|
18419
|
+
onClick: (event) => {
|
|
18420
|
+
handleClick(index);
|
|
18402
18421
|
},
|
|
18403
|
-
|
|
18404
|
-
|
|
18405
|
-
|
|
18406
|
-
|
|
18407
|
-
|
|
18408
|
-
|
|
18409
|
-
|
|
18410
|
-
|
|
18411
|
-
|
|
18412
|
-
|
|
18413
|
-
|
|
18422
|
+
children: [
|
|
18423
|
+
!isLoaded && /* @__PURE__ */ u(Loading, {}),
|
|
18424
|
+
/* @__PURE__ */ u(
|
|
18425
|
+
"img",
|
|
18426
|
+
{
|
|
18427
|
+
src: "".concat(imgBasePath).concat(page.image_url),
|
|
18428
|
+
alt: page.description,
|
|
18429
|
+
className: "thumbnail-image",
|
|
18430
|
+
onLoad: () => {
|
|
18431
|
+
handleImageLoad(page);
|
|
18432
|
+
},
|
|
18433
|
+
onError: (error2) => {
|
|
18434
|
+
handleImageError(page, error2);
|
|
18435
|
+
}
|
|
18436
|
+
}
|
|
18437
|
+
),
|
|
18438
|
+
/* @__PURE__ */ u("div", { className: "thumbnail-page-number", children: index + 1 })
|
|
18439
|
+
]
|
|
18440
|
+
},
|
|
18441
|
+
page.image_url
|
|
18442
|
+
);
|
|
18443
|
+
})
|
|
18444
|
+
}
|
|
18445
|
+
)
|
|
18446
|
+
] })
|
|
18414
18447
|
] });
|
|
18415
18448
|
};
|
|
18416
18449
|
const ImagePage = (props) => {
|
|
@@ -18517,7 +18550,6 @@ const FilePreviewImageGroup = (props) => {
|
|
|
18517
18550
|
const state = controller.state;
|
|
18518
18551
|
const contentRef = A(null);
|
|
18519
18552
|
const isScrolling = useSignal(false);
|
|
18520
|
-
const [loadedPages, setLoadedPages] = d$2(/* @__PURE__ */ new Set());
|
|
18521
18553
|
const computeClosestPage = () => {
|
|
18522
18554
|
if (contentRef.current) {
|
|
18523
18555
|
const containerRect = contentRef.current.getBoundingClientRect();
|
|
@@ -18573,8 +18605,8 @@ const FilePreviewImageGroup = (props) => {
|
|
|
18573
18605
|
}
|
|
18574
18606
|
};
|
|
18575
18607
|
const preloadImages = () => {
|
|
18576
|
-
const
|
|
18577
|
-
|
|
18608
|
+
const preloadPages = state.value.items.slice(0, 2);
|
|
18609
|
+
preloadPages.forEach((page) => {
|
|
18578
18610
|
if (page) {
|
|
18579
18611
|
const img = new Image();
|
|
18580
18612
|
img.src = "".concat(imgBasePath).concat(page.image_url);
|
|
@@ -18631,6 +18663,7 @@ const FilePreviewImageGroup = (props) => {
|
|
|
18631
18663
|
};
|
|
18632
18664
|
const handlePageClick = (pageIndex) => {
|
|
18633
18665
|
controller.updateState({ currentPage: pageIndex });
|
|
18666
|
+
updateIsScrolling();
|
|
18634
18667
|
scrollToPageWhenStable(pageIndex);
|
|
18635
18668
|
};
|
|
18636
18669
|
const handleInput = (e2) => {
|
|
@@ -18704,7 +18737,7 @@ const FilePreviewImageGroup = (props) => {
|
|
|
18704
18737
|
handleScroll();
|
|
18705
18738
|
},
|
|
18706
18739
|
children: state.value.items && state.value.items.length > 0 && state.value.items.map((page, index) => {
|
|
18707
|
-
const bufferRange =
|
|
18740
|
+
const bufferRange = 3;
|
|
18708
18741
|
const startRange = Math.max(
|
|
18709
18742
|
0,
|
|
18710
18743
|
state.value.currentPage - bufferRange
|
|
@@ -18714,11 +18747,8 @@ const FilePreviewImageGroup = (props) => {
|
|
|
18714
18747
|
state.value.currentPage + bufferRange
|
|
18715
18748
|
);
|
|
18716
18749
|
const shouldRender = index >= startRange && index <= endRange;
|
|
18717
|
-
|
|
18718
|
-
|
|
18719
|
-
if (!loadedPages.has(index)) {
|
|
18720
|
-
setLoadedPages((prev) => new Set(prev).add(index));
|
|
18721
|
-
}
|
|
18750
|
+
if (!shouldRender) {
|
|
18751
|
+
return null;
|
|
18722
18752
|
}
|
|
18723
18753
|
return /* @__PURE__ */ u(
|
|
18724
18754
|
ImagePage,
|
|
@@ -18726,9 +18756,9 @@ const FilePreviewImageGroup = (props) => {
|
|
|
18726
18756
|
page,
|
|
18727
18757
|
index,
|
|
18728
18758
|
state,
|
|
18729
|
-
isShowImage:
|
|
18759
|
+
isShowImage: true
|
|
18730
18760
|
},
|
|
18731
|
-
|
|
18761
|
+
page.image_url
|
|
18732
18762
|
);
|
|
18733
18763
|
})
|
|
18734
18764
|
}
|